package com.aurora.oa.work.presenter;


import com.aurora.oa.Constants.AuroraConstants;
import com.aurora.oa.bean.HttpResult;
import com.aurora.oa.home.bean.ArticleBean;
import com.aurora.oa.listener.OnRequestHttpDataListener;
import com.aurora.oa.model.RequestHttpModel;
import com.aurora.oa.model.RequestHttpModelImpl;
import com.aurora.oa.work.view.WorkFragmentView;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;

/**
* Created by Administrator on 2017/03/14
*/

public class WorkFragmentPresenterImpl implements WorkFragmentPresenter{

    WorkFragmentView workFragmentView;
    RequestHttpModel requestHttpModel;
    public WorkFragmentPresenterImpl(WorkFragmentView workFragmentView) {
        this.workFragmentView = workFragmentView;
        requestHttpModel = new RequestHttpModelImpl();
    }

    /**
     * 请求网络数据
     */
    @Override
    public void getWorkMainDataHttp() {

        requestHttpModel.requestHttpDataString(AuroraConstants.GET_FIRST_ARTICLE,new OnRequestHttpDataListener(){

            @Override
            public void onRequestDataSuccess(String body) {
                Gson gson = new Gson();
                Type type = new TypeToken<HttpResult<ArticleBean>>(){}.getType();
                HttpResult<ArticleBean> result = gson.fromJson(body,type);
                workFragmentView.refreshWorkMainPage(result.obj);
            }

            @Override
            public void onRequestDataFail(String message) {

            }
        });

    }

}